// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0


// based on https://github.com/slint-ui/slint/issues/1327#issuecomment-1151244049

export component RipplCircle inherits Rectangle {
    in-out property <length> radius: 0;
    in-out property <length> mx: 0;
    in-out property <length> my: 0;
    in-out property <float> fwidth: 0;
    in-out property <float> fheight: 0;
    in-out property <bool> running: false;
    width: root.radius * 2;
    height: root.radius * 2;
    x: root.mx - root.width / 2;
    y: root.my - root.height / 2;
    background: rgba(0,0,0, 0.5);
    border-radius: root.width / 2;

    in-out property <float> counter: 0;
    animate counter { duration: 800ms; }

    states [
        ripple when root.counter > 0 && root.counter < 0.1 : {
            radius: 100px;
            opacity: 0.;
            running: true;
        in  {
            animate radius { duration: 800ms; }
            animate opacity { duration: 800ms; }
        }
        }
    ]
}

export component InkEffect inherits Rectangle {

    preferred-width: 200px;
    preferred-height: 200px;
    background: white;
    clip: true;

    circle1 := RipplCircle {}
    // un commenting the next line causes macro proc panick
    circle2 := RipplCircle { background: green; }


    tch := TouchArea {
        width: parent.width;
        height: parent.height;
        pointer-event(ev) => {
            if (ev.kind == PointerEventKind.down && ev.button == PointerEventButton.left) {
                if (!circle1.running) {
                    circle1.mx = self.mouse-x;
                    circle1.my = self.mouse-y;
                    circle1.fwidth = parent.width / 1px;
                    circle1.fheight = parent.height / 1px;
                    circle1.counter = circle1.counter == 0 ? 0.1 : 0;
                }
            }
        }

    }
}
